package com.kerrykidz.filemanagement.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.kerrykidz.filemanagement.dao.model.SingleTicketUserEntity;
import com.kerrykidz.filemanagement.service.ISingleTicketService;
import com.kerrykidz.membership.dao.model.CusGuaEntity;
import com.kerrykidz.membership.dao.model.CusMemEntity;
import com.kerrykidz.membership.service.IMemberService;
import com.rdp.framework.exception.RDPException;

@Controller
@RequestMapping("filemanagement")
public class SingleTicketController {
	@Autowired
	private ISingleTicketService singleTicketService;
	@Autowired
	private IMemberService memberService;
	
	@RequestMapping("/listSingelTicket")
	public ModelAndView listSingelTicket(@RequestParam(value = "condition",required=false) String condition,
			@RequestParam(value = "status",required=false) String status,
			@RequestParam(value = "startDate",required=false) String startDate,
			@RequestParam(value = "endDate",required=false) String endDate){
		List<SingleTicketUserEntity> list=singleTicketService.listSingelTicket(condition, status, startDate, endDate);
		return new ModelAndView("file/file_single", "list", list);
	}
	
	/**
	 * 跳转到单次票管理
	 * @return
	 */
	@RequestMapping("/listViewSingelTicket")
	public ModelAndView listSingelTicket(){
		List<SingleTicketUserEntity> list=singleTicketService.listSingelTicket(null,null,null,null);
		return new ModelAndView("file/file_single", "list", list);
	}
	
	/**
	 * 单次票列表模式
	 * @return
	 */
	@RequestMapping("/listModelSingelTicket")
	@ResponseBody
	public List<SingleTicketUserEntity> listModelSingelTicket(@RequestParam(value = "condition",required=false) String condition,
			@RequestParam(value = "status",required=false) String status,
			@RequestParam(value = "startDate",required=false) String startDate,
			@RequestParam(value = "endDate",required=false) String endDate){
		List<SingleTicketUserEntity> list=singleTicketService.listSingelTicket(condition, status, startDate, endDate);
//		Map<String,Object> item=new HashMap<String,Object>();
//		item.put("MODI_TIME", new Date(System.currentTimeMillis()));
//		list.add(item);
		return list;
	}
	
	/**
	 * 单次票视图模式查询
	 * @return
	 */
	@RequestMapping("/searchViewSingelTicket")
	@ResponseBody
	public List<SingleTicketUserEntity> listViewSingelTicket(@RequestParam(value = "condition",required=false) String condition,
			@RequestParam(value = "status",required=false) String status,
			@RequestParam(value = "startDate",required=false) String startDate,
			@RequestParam(value = "endDate",required=false) String endDate){
		List<SingleTicketUserEntity> list=singleTicketService.listSingelTicket(condition, status, startDate, endDate);
		return list;
	}
	
	/**
	 * 跳转到档案管理页面
	 * @return
	 */
	@RequestMapping("/filemanagement")
	public String fileManagement(){
		return "file/file_single_x";
	}
	
	/**
	 * 获取单次票用户详细信息
	 * @return
	 * @throws RDPException
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping("/getSingleUserDetail")
	@ResponseBody
	public ModelAndView queryMemberDetail(@RequestParam(value="memberId",required=true)String memberId) throws RDPException {

		ModelAndView mv = new ModelAndView("file/file_single_du");
		//会员、非会员信息
		CusMemEntity member = memberService.findMemberById(memberId);
		mv.addObject("member", member);
		
		//监护人列表
		List<CusGuaEntity> guaList = memberService.findGuaByMemberId(memberId);
		mv.addObject("guaList", guaList);
		
		//玩伴票列表
		
		//单次票商品列表
		
		return mv;
		
	}
}
